package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.JobOption;
import com.itheima.pojo.StudentOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private EmpMapper empMapper;
    
    /***
     * 班级人数统计
     * @return
     */
    @Override
    public StudentOption getStudentCountData() {
        //查询数据
        List <Map<String,Object>> list = studentMapper.countStudentCountData();

        //转换数据
        return new StudentOption(
                list.stream().map(m->m.get("name")).collect(Collectors.toList()),
                list.stream().map(m->m.get("num")).collect(Collectors.toList())
        );
    }

    /***
     * 学员学历统计
     * @return
     */
    @Override
    public List<Map> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }


    @Override
    public JobOption getEmpJobData() {
        List<Map<String,Object>> list = empMapper.countEmpJobData();
// dataMap 是一个实现了 Map<String, Object> 接口的对象 如:
//         Map<String, Object> dataMap = new HashMap<>();
//     dataMap.put("pos", "Engineer");
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("total")).toList();
//        public class JobOption {
//    private List<Object> jobList;
//    private List<Object> dataList;
//
//    // 构造函数
//    public JobOption(List<Object> jobList, List<Object> dataList) {
//        this.jobList = jobList;
//        this.dataList = dataList;
//    } 可以通过new对象将参数传进去
        return new JobOption(jobList, dataList);
    }
    //男女
    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }
}
